package com.sgcc.csc.dao;

import com.sgcc.csc.dto.*;
import com.sgcc.csc.framework.jdbc.client.SqlClient;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:TestDao
 * Package:com.sgcc.csc.dao
 * Description:
 *
 * @date:2021/2/25 16:33
 * @author:cuiyang
 */
@Repository
public class ShiroDao {

    public static final String NAMESPACE = "shiro.";

    @Resource
    private SqlClient sqlClient;


    /**
     * 获得密码
     */
    public List<DataVUserDto> getPassword(String username){
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("username",username);
        return sqlClient.queryForList(NAMESPACE + "getPassword",paramMap, DataVUserDto.class);
    };

    /**
     * 获得角色权限
     */
    public List<DataVUserDto> getRole(String username){
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("username",username);
        return sqlClient.queryForList(NAMESPACE + "getRole",paramMap, DataVUserDto.class);
    };

    /**
     * 修改密码
     */
    public void updatePassword(String username,String newPassword){
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("username",username);
        paramMap.put("password",newPassword);
        sqlClient.queryForList(NAMESPACE + "updatePassword",paramMap, DataVUserDto.class);
    };

    /**
     * 获得存在的用户
     */
    public List<DataVUserDto> getUser(){
        Map<String,Object> paramMap = new HashMap<>();
        return sqlClient.queryForList(NAMESPACE + "getUser",paramMap, DataVUserDto.class);
    };

    /**
     * 封号
     */
    public void banUser(String username){
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("username",username);
        sqlClient.queryForList(NAMESPACE + "banUser",paramMap, DataVUserDto.class);
    };

    /**
     * 检查用户状态
     */
    public List<DataVUserDto> checkUserBanStatus(String username){
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("username",username);
        return sqlClient.queryForList(NAMESPACE + "checkUserBanStatus",paramMap, DataVUserDto.class);
    };

    /**
     * 获得用户角色默认的权限
     */
    public List<DataVUserDto> getRolePermission(String username){
        Map<String,Object> paramMap = new HashMap<>();
        return sqlClient.queryForList(NAMESPACE + "getRolePermission",paramMap, DataVUserDto.class);
    };

    /**
     * 获得用户的权限
     */
    public List<DataVUserDto> getPermission(String username){
        Map<String,Object> paramMap = new HashMap<>();
        return sqlClient.queryForList(NAMESPACE + "getPermission",paramMap, DataVUserDto.class);
    };

    /**
     * 获取表名 getTaleName
     */
    public List<String> getTaleName(){
        Map<String,Object> paramMap = new HashMap<>();
        return sqlClient.queryForList(NAMESPACE + "getTaleName",paramMap, String.class);
    };


}
